package appconfig

import (
	"fmt"
	"github.com/spf13/viper"
)

type AppConf struct {
	Mysql
	Redis
	ALIYun
	Es
	QiNiuYun
	ALiPay
}
type QiNiuYun struct {
	AccessKey string
	SecretKey string
	Bucket    string
	YuMing    string
}
type Mysql struct {
	Name     string
	Password string
	Host     string
	Port     int
	Database string
}
type Redis struct {
	Addr     string
	Password string
	DB       int
}
type ALIYun struct {
	AccessKeyId     string
	AccessKeySecret string
}
type Es struct {
	Addresses string
}
type ALiPay struct {
	PrivateKey string
	AppId      string
	NotifyURL  string
	ReturnURL  string
}

var Conf *AppConf

func Init() {
	viper.SetConfigFile("./appconfig/dev.yaml")
	err := viper.ReadInConfig()
	if err != nil {
		panic("读取配置文件失败")
	}
	err = viper.Unmarshal(&Conf)
	if err != nil {
		panic("解析配置文件失败")
	}
	fmt.Println(Conf)
	fmt.Println("读取配置文件成功")
}
